//
//  HelloLoverPageView.swift
//  SwiftUIDemo
//
//  Created by zhouzuosong on 2020/8/22.
//  Copyright © 2020 Kael. All rights reserved.
//

import SwiftUI

struct HelloLoverPageView: View {
    @State var unlock = false
    @State var open = false
    
    var body: some View {
        VStack (spacing: 20) {
            Text("Hello, Lover!").font(.title)
            
            Spacer()
            
            VStack{
                Button(action: {
                    withAnimation {
                        self.unlock.toggle()
                    }
                }, label: {
                    Image(systemName: self.unlock ? "lock.open" : "lock")
                        .font(.system(size: 30))
                })
                .padding()
                
                
                GeometryReader(content: { geometry in
                    ZStack{
                        
                        Button(action: {}, label: {
                            VStack{

                                Text("Hello Linda").font(.title).padding()
                                Image(systemName: self.unlock ? "heart.fill" : "heart").foregroundColor(.red)
                            }
                            .frame(maxWidth: .infinity, minHeight: 300)
                            .font(.system(size: 70))
                            .scaleEffect(self.unlock ? 2 : 0.5)
                            .opacity(self.unlock ? 1 : 0)
                            .animation( Animation.easeOut.delay(self.unlock ? 1 : 0))

                        })
                        
                        HStack (spacing: 0){
                            Rectangle()
                                .fill(self.unlock ? Color.green : Color.red)
                                .offset(x: self.unlock ? -geometry.size.width : 0)
                            Rectangle()
                                .fill(self.unlock ? Color.green : Color.red)
                                .offset(x: self.unlock ? geometry.size.width : 0)
                        }
                        
                    }
                })
                
                Spacer()
            }
            .animation(.default)
        }
    }
}

struct HelloLoverPageView_Previews: PreviewProvider {
    static var previews: some View {
        HelloLoverPageView()
    }
}
